package com.yd.mvc.pc.goodsTypeController;

import com.yd.app.service.mobile.goodsTypeService.MGoodsTypeService;
import com.yd.app.service.pc.gStyleService.GTypeOneService;
import com.yd.app.util.BusinessException;
import com.yd.domain.business.GTypeOne;
import com.yd.domain.business.PinXing;
import com.yd.domain.commom.PageModel;
import com.yd.domain.searchParam.GTypeOneParam;
import com.yd.domain.sys.Logger;
import com.yd.mvc.baseController.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Author: zy
 * @Desc: 商品类型一级二级三级分类
 * @Date:  2018/4/28
 * @Param
 */
@RestController
@RequestMapping(value = "/api/gTypeOne")
public class GoodsTypeOneController extends BaseController{
    @Autowired
    private GTypeOneService gTypeOneService;
    @Autowired
    private MGoodsTypeService mGoodsTypeService;

    /**
     * @Author: zy
     * @Desc: 查询商品导航三级
     * @Date:  2018/4/28
     * @Param
     */
    @RequestMapping(value = "/getTypeOne", method = RequestMethod.GET)
    public List<GTypeOne> getTypeOne() throws BusinessException {
       List<GTypeOne> list=gTypeOneService.getTypeOne();
        return list;
    }

    @RequestMapping(value = "/getSecondType/{pId}/{level}", method = RequestMethod.GET)
    public GTypeOne getSecondType(@PathVariable("pId")String pId,@PathVariable("level")String level) throws BusinessException {
        GTypeOne gTypeOne=gTypeOneService.getSecondType(pId,level);
        return gTypeOne;
    }

    @RequestMapping(value = "/getTypeAndStyle/{type}/{gstyle}", method = RequestMethod.GET)
    public GTypeOne getTypeAndStyle(@PathVariable("type")String type,@PathVariable("gstyle")String gstyle) throws BusinessException {
        GTypeOne gTypeOne=gTypeOneService.getTypeAndStyle(type,gstyle);
        return gTypeOne;
    }
    /**
     * @Author: zy
     * @Desc: 查询二级
     * @Date:  2018/5/18
     * @Param
     */
    @RequestMapping(value = "/getTypeByGoodType/{type}", method = RequestMethod.GET)
    public GTypeOne getTypeByGoodType(@PathVariable("type")String type) throws BusinessException {
        GTypeOne gTypeOne=gTypeOneService.getTypeByGoodType(type);
        return gTypeOne;
    }
    /**
     * @Author: zy
     * @Desc: 查询三级
     * @Date:  2018/5/18
     * @Param
     */
    @RequestMapping(value = "/getStyleByGoodStyle/{gstyle}", method = RequestMethod.GET)
    public GTypeOne getStyleByGoodStyle(@PathVariable("gstyle")String gstyle) throws BusinessException {
        GTypeOne gTypeOne=gTypeOneService.getStyleByGoodStyle(gstyle);
        return gTypeOne;
    }
    /**
     * @Author: zy
     * @Desc: 新增
     * @Date:  2018/5/2
     * @Param
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public void addGoods(@RequestBody GTypeOne gTypeOne)  {
        gTypeOneService.addGTypeOne(gTypeOne);
    }
    /**
     * @Author: zy
     * @Desc: 修改
     * @Date:  2018/5/2
     * @Param
     */
    @RequestMapping(value = "/update", method = RequestMethod.PUT)
    public void updateGType(@RequestBody GTypeOne gType,HttpServletRequest request){
        try {
            gTypeOneService.updateGTypeOne(gType);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    /**
     * @Author: zy
     * @Desc: 删除
     * @Date:  2018/5/2
     * @Param
     */
    @RequestMapping(value = "/delete/{id}", method = RequestMethod.DELETE)
    public void deleteGType(@PathVariable("id") String id,HttpServletRequest request){
        try {
            gTypeOneService.deleteGTypeOne(id);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    /**
     * @Author: zy
     * @Desc: 根据ID查询
     * @Date:  2018/5/2
     * @Param
     */
    @RequestMapping(value = "/getById/{id}", method = RequestMethod.GET)
    public GTypeOne getById(@PathVariable("id") String id,HttpServletRequest request){
        GTypeOne g= gTypeOneService.getById(id);
        return g;
    }
    /**
     * @Author: zy
     * @Desc: 分页查询
     * @Date:  2018/5/2
     * @Param
     */
    @RequestMapping(value = "/list/{pageIndex}/{pageSize}", method = RequestMethod.POST)
    public PageModel getGTypeOneList(@RequestBody GTypeOneParam gTypeParam, @PathVariable("pageIndex")int pageIndex, @PathVariable("pageSize")int pageSize){
        PageModel pm=gTypeOneService.getGTypeOneList(gTypeParam,pageIndex,pageSize);
        return pm;
    }

    /**
     * @Author: zy
     * @Desc: 查询商品导航三级
     * @Date:  2018/4/28
     * @Param
     */
    @RequestMapping(value = "/getGoodNav", method = RequestMethod.GET)
    public List<GTypeOne> getGoodNav() throws BusinessException {
        List<GTypeOne> list=mGoodsTypeService.getGoodNav();
        return list;
    }
    /**
     * @Author: zy
     * @Desc: 查询商品导航两级
     * @Date:  2018/4/28
     * @Param
     */
    @RequestMapping(value = "/getGoodNavTwo", method = RequestMethod.GET)
    public List<GTypeOne> getGoodNavTwo() throws BusinessException {
        List<GTypeOne> list=mGoodsTypeService.getGoodNavTwo();
        return list;
    }
    /***********************************************品型表的增删改查*****************************************************/
    /**
     * @Author: zy
     * @Desc: 品型添加
     * @Date:  2018/5/9
     * @Param
     */
    @RequestMapping(value = "/addPX", method = RequestMethod.POST)
    public void addPinXing(@RequestBody PinXing pinXing)  {
        gTypeOneService.addPinXing(pinXing);
    }
    /**
     * @Author: zy
     * @Desc: 修改
     * @Date:  2018/5/9
     * @Param
     */
    @RequestMapping(value = "/updatePX", method = RequestMethod.PUT)
    public void updatePX(@RequestBody PinXing pinXing,HttpServletRequest request){
        try {
            gTypeOneService.updatePX(pinXing);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    /**
     * @Author: zy
     * @Desc: 删除
     * @Date:  2018/5/9
     * @Param
     */
    @RequestMapping(value = "/deletePX/{id}", method = RequestMethod.DELETE)
    public void deletePX(@PathVariable("id") String id,HttpServletRequest request){
        try {
            gTypeOneService.deletePX(id);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    /**
     * @Author: zy
     * @Desc: 根据样式查询品型
     * @Date:  2018/5/11
     * @Param
     */

    @RequestMapping(value = "/getPxByStyle/{pId}", method = RequestMethod.GET)
    public List<PinXing> getPxByStyle(@PathVariable("pId") String pId,HttpServletRequest request){
        List<PinXing> list=mGoodsTypeService.getPxByPid(pId);
        return list;
    }
}
